package com.example.zlw.dem5;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;

/**
 * @program: Zlw
 * @description:
 * @author: 诸葛龙辰
 * @create: 2022-11-04 21:10
 **/
public class StreamMethod {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student("李相赫", 18, "T1"));
        list.add( new Student("UzI", 18, "中国"));
        list.add( new Student("刘德华", 20, "中国"));
        list.add(new Student("骚猪", 23, "中国"));
        list.add( new Student("野猪佩奇", 35, "日本"));
        list.add(new Student("野猪乔治", 11, "印度"));
        Predicate<Student> predicate= item->item.getAge()>18;
        Consumer<Student> consumer= item-> System.out.println(item);
        //filter是属于我们Stream中的中间操作方法，
        // forEach和count属于我们Stream的终止方法
        list.stream().filter(predicate).forEach(consumer);
        Predicate<Student> predicate1=item->item.getAddress().equals("中国");
        long count = list.stream().filter(predicate1).count();
        System.out.println(count);
    }
}
class Student{
    private String name;
    private int age;
    private String address;

    public Student() {
    }

    public Student(String name, int age, String address) {
        this.name = name;
        this.age = age;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", address='" + address + '\'' +
                '}';
    }


}
